//
//  FoodMainModel.m
//  ArtOfLiving
//
//  Created by xalo on 16/4/29.
//  Copyright © 2016年 刘虎. All rights reserved.
//

#import "FoodMainModel.h"
#import "FoodNoticeModel.h"
#import "FoodProcedureModel.h"
#import "FoodComponentModel.h"
#import "FoodNutritionDataModel.h"

#define kInitFoodNoticeModel [[FoodNoticeModel alloc] init]

@implementation FoodMainModel

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        _timeMArr = [[NSMutableArray alloc] init];
        _effectMArr = [[NSMutableArray alloc] init];
        _meatMArr = [[NSMutableArray alloc] init];
        _otherMArr = [[NSMutableArray alloc] init];
        _procedureMArr = [[NSMutableArray alloc] init];
        _componentMArr = [[NSMutableArray alloc] init];
        _nutritionMArr = [[NSMutableArray alloc] init];
        _authorModel = [[FoodAuthorModel alloc] init];
    }
    return self;
}


- (void)setValue:(id)value forUndefinedKey:(NSString *)key{
    
    if ([key isEqualToString:@"id"]) {
        
        self.ID = value;
    }
    if ([key isEqualToString:@"nutrition_set"]) {
        
        NSArray *allKeys = [value allKeys];
        for (NSString *key in allKeys) {
            
            FoodNutritionDataModel *model = [[FoodNutritionDataModel alloc] init];
            [model setValuesForKeysWithDictionary:[value objectForKey:key]];
            [self.nutritionMArr addObject:model];
        }
    }
    if ([key isEqualToString:@"component_set"]) {
        
        for (NSDictionary *dic in value) {
            
            FoodComponentModel *model = [[FoodComponentModel alloc] init];;
            [model setValuesForKeysWithDictionary:dic];
            [self.componentMArr addObject:model];
        }
    }
    if ([key isEqualToString:@"author"]) {
        
        [self.authorModel setValuesForKeysWithDictionary:value];
    }
    if ([key isEqualToString:@"time_labels"]) {
        
        for (NSDictionary *dic in value) {
            
            FoodNoticeModel *model = kInitFoodNoticeModel;
            [model setValuesForKeysWithDictionary:dic];
            [self.timeMArr addObject:model];
        }
    }
    if ([key isEqualToString:@"effect_labels"]) {
        
        for (NSDictionary *dic in value) {
            
            FoodNoticeModel *model = kInitFoodNoticeModel;
            [model setValuesForKeysWithDictionary:dic];
            [self.effectMArr addObject:model];
        }
    }
    if ([key isEqualToString:@"meat_labels"]) {
        
        for (NSDictionary *dic in value) {
            
            FoodNoticeModel *model = kInitFoodNoticeModel;
            [model setValuesForKeysWithDictionary:dic];
            [self.meatMArr addObject:model];
        }
    }
    if ([key isEqualToString:@"other_labels"]) {
        
        for (NSDictionary *dic in value) {
            
            FoodNoticeModel *model = kInitFoodNoticeModel;
            [model setValuesForKeysWithDictionary:dic];
            [self.otherMArr addObject:model];
        }
    }
    if ([key isEqualToString:@"procedure_set"]) {
        
        for (NSDictionary *dic in value) {
            
            FoodProcedureModel *model = [[FoodProcedureModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [self.procedureMArr addObject:model];
        }
    }
    
}



@end
